<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<head>
<link href="${pageContext.request.contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">

<!-- 형규 css -->
<style>
	.td-align{
			width:20%;
			text-align:center;
	}
</style>

<!-- jQuery할때 아래 라이브러.js 절대 까먹지말기..... 안먹힘.... -->
<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>


<script type="text/javascript">
	
	//게시판카테고리 삭제 AJAX
	function delete_boardtype(selectPageNo, boardTypeNo){		
		$.ajax({
			url : 'deleteboardtype',
			type : 'post',
			async : true,
			data : {boardTypeNo:boardTypeNo}, //실어보낼 data ex) data:{키값:값}
		});
		
		alert("삭제가 완료되었습니다.");
		
		//다시 화면뿌려주기
		get_JSON(selectPageNo);
	}
	
	//게시판카테고리 수정 AJAX
	function name_modify(selectPageNo, boardTypeNo){
		var selectStr = '#boardtype_name' + boardTypeNo; //jQuery 들어갈 String
		var boardTypeName = $(selectStr).val();
		$.ajax({
			url : 'setboardtypenamemodify',
			type : 'post',
			async : true,
			data : {boardTypeNo:boardTypeNo, boardTypeName:boardTypeName}, //실어보낼 data ex) data:{키값:값}
		});
		
		alert("수정이 완료되었습니다.");
		
		//다시 화면뿌려주기
		get_JSON(selectPageNo);
		
	}
	
	//게시판카테고리 추가 AJAX
	function name_add(selectPageNo){
		var boardTypeName = $("#add_boardtype_name").val();
		$.ajax({
			url : 'setboardtypenameadd',
			type : 'post',
			async : true,
			data : {boardTypeName:boardTypeName}, //실어보낼 data ex) data:{키값:값}
		});
		
		alert("보드카테고리에 [" + boardTypeName + "] 가 추가되었습니다.");
		
		//다시 화면뿌려주기
		get_JSON(selectPageNo);
	}
	
	//게시판카테고리 리스트가져오기 AJAX
	function get_JSON(selectPageNo) {
		$.ajax({
			url : 'getajaxadminboardtype',
			type : 'post',
			async : true,
			data : {selectPageNo:selectPageNo}, //실어보낼 data ex) data:{키값:값}
			dataType : 'JSON',
			success : function(adminListBeans) {
				var out = '';
				
				//~~~~~~~~ 시작 ~~~~~~~~
				out += '<table border="1" class="table table-striped" style="background-color:#FE980F;">'; 

				out += '<tr><td class="td-align">번호</td> <td class="td-align">게시판명</td> <td class="td-align">게시판명 수정</td> <td class="td-align">삭제</td></tr>';

				//카테고리리스트 뿌려주기
				$.each(adminListBeans.list, function (index, boardTypeBeans){
					out += '<tr>';
					out += '<td style="width:20%" class="td-align">' + boardTypeBeans.btype_no + '</td>';
					out += '<td style="width:30%" class="td-align">' + boardTypeBeans.btype_name + '</td>';
					out += '<td style="width:40%" class="td-align">';
					out += '<input type="text" id="boardtype_name' + boardTypeBeans.btype_no + '" value="' + boardTypeBeans.btype_name + '"/>&nbsp;';
					out += '<input type="button" value="수정" onClick="javascript:name_modify(' + adminListBeans.selectPageNo + ', ' + boardTypeBeans.btype_no + ')"/>';
					out += '</td>';
					out += '<td style="width:10%"class="td-align"><input type="button" value="삭제" onClick="javascript:delete_boardtype(' + adminListBeans.selectPageNo + ', ' + boardTypeBeans.btype_no + ')"/></td></tr>';
				});
				
				//~~~~~~~~ 페이지뿌려주기 시작부분 ~~~~~~~~
				out += '<tr><td align="center" colspan="4" style="padding-top:15px; padding-bottom:15px">';
				
				//왼쪽그룹존재여부 (스트링→인트:parseInt(스트링숫자))
				if(adminListBeans.showPreviousGroup){
					out += '<a href="javascript:get_JSON(' + adminListBeans.preGroupStartPageNo + ')">◀</a>&nbsp;&nbsp;';
				}
				
				//페이지번호 뿌려주기
				for(var no = adminListBeans.startPageNo; no <= adminListBeans.endPageNo; no++){
					if(no==adminListBeans.selectPageNo){
						out += '<a href="javascript:get_JSON(' + no + ')"><font color="red"><strong>' + no + '</strong></font></a>&nbsp;&nbsp;';
					}
					else{
						out += '<a href="javascript:get_JSON(' + no + ')">' + no + '</a>&nbsp;&nbsp;';
					}
				}
				
				//오른쪽그룹존재여부
				if(adminListBeans.showNextGroup){
					out += '<a href="javascript:get_JSON(' + adminListBeans.nextGroupStartPageNo + ')">▶</a>&nbsp;&nbsp;';
				}
				
				out += '</td></tr>';
				out += '</table>';
				out += '&nbsp;&nbsp;&nbsp;제조사&nbsp;추가&nbsp;:&nbsp';
				out += '<input type="text" id=add_boardtype_name>&nbsp;<input type="button" onClick="javascript:name_add(' + adminListBeans.selectPageNo + ')" value="추가">';
				
				//닫기버튼
				out += '<span style="float:right"><input type="button" onClick="javascript:selfclose()" value="닫기">';
				out += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
				
				$("#cbody").html(out); //id값에다가 html 때려넣기
			}
		});
	}
	
	function selfclose(){
		window.close();
	}
	
</script>
</head>

<body onresize="parent.resizeTo(730,780)" onload="javascript:get_JSON(1)">

	<div style="margin-top:30px; margin-bottom:30px"><jsp:include page="../admin/admin_top.jsp"></jsp:include></div>
	
	<div id = cbody></div>


	<%-- Ajax 안쓸때 JSTL 로 했던 폼
	
	<table>
		<tr><td>번호</td> <td>아이디</td> <td>이름</td> <td>등급</td> <td>회원탈퇴</td></tr>
		<!-- 페이지리스트 (리스트안에 MemberBeans들이 있음)-->
		<c:forEach var="memberBeans" items="${adminListBeans.list}" varStatus="status">
				<tr><td>${memberBeans.member_no}</td> <td>${memberBeans.member_id}</td> <td>${memberBeans.member_name}</td> <td>${memberBeans.member_grade}</td> <td><input type="button" value="회원탈퇴"/> </td></tr>
		</c:forEach>
		
		<!-- 페이지넘버라인 -->
		<tr><td align="center" colspan="5" style="padding-top:30px">
		<c:if test="${adminListBeans.showPreviousGroup}">
			<a href="#">◀</a>&nbsp;&nbsp;					
		</c:if>
		
		<c:forEach var="no" begin="${adminListBeans.startPageNo}" end="${adminListBeans.endPageNo}">
			<c:if test="${no==adminListBeans.selectPageNo}">
				<font color='red'><strong>${no}</strong></font>&nbsp;&nbsp;
			</c:if>
			<c:if test="${no!=adminListBeans.selectPageNo}">
				${no}&nbsp;&nbsp;
			</c:if>
		</c:forEach>
		
		<c:if test="${adminListBeans.showNextGroup}">
			<a href="#">▶</a>&nbsp;&nbsp;					
		</c:if>
		
		
		</td></tr>
	</table>
	
	--%>

</body>
</html>